<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="客户ID">
        <el-input v-model="form.custID"></el-input>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="form.cname"></el-input>
      </el-form-item>
      <el-form-item label="联系方式">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="form.address"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">确认</el-button>
        <el-button @click="reset">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";
import qs from "qs";
export default {
  data() {
    return {
      form: {
        cname: "",
        custID: "",
        phone: "",
        address: "",
      },
      money: 3000,
    };
  },
  methods: {
    onSubmit() {
      axios({
        url: "http://localhost:3000/addCustomer",
        method: "post",
        data: qs.stringify({
          cname: this.form.cname,
          custID: this.form.custID,
          phone: this.form.phone,
          address: this.form.address,
        })
      })
      this.$message({
          message: '添加成功！',
          type: 'success'
        });
      history.back()
    },
    reset() {
      this.$router.push("/customer");
    },
  },
};
</script>

<style scoped>
</style>